//上传文件
function uploadBath() {
	$.ajaxFileUpload({
		url : getHttpRequestPath("main/uploadFile"),
		secureuri : false,
		fileElementId : 'fileToUpload',
		dataType : 'json',
//		data : {name:'logan.jpg', id:'i22222d'},
		data : {fileToUploadId:'fileToUpload', name:'i22222d'},
		success : function(data, status) {
			var msg = JSON.parse(data, function(key, value) {
				return value;
			});

			if (msg.STATE == "NotFolder") {
				alert("服务器未指定路径!请联系管理员");
			}
			if (msg.STATE == "empty") {
				alert("不能上传空文件");
			}
			if (msg.STATE == "error") {
				alert("上传失败");
			}
			if (msg.STATE == "success") {
				$('#uploadMsg').html('上传成功,点击"导入"按钮 开始执行');
				$('#filePathId').val(msg.FILEPATH);
				$('#InductionButtons').linkbutton({
					disabled : false
				});
			}
		},
		error : function(data, status, e) {
			alert("is error");
		}
	});
	return false;
}

//导入数据
function saveBatch() {
	var filePath = $('#filePathId').val();
	if (filePath == "") {
		$.messager.alert('系统提示', '请先上传数据文件');
		return;
	}
	$('#batchDlg').mask("正在处理...");
	$.post(getHttpRequestPath("system/importUsers"), {
		filePath : filePath
	}, function(response) {
		var msg = JSON.parse(response, function(key, value) {
			return value;
		});
		if (msg.STATE.toLowerCase() == "success") {
			$.messager.alert('系统提示', '保存成功！');
			$('#uploadMsg').html("上传成功！");

			var resultMsg = '总共' + msg.totleCount + '条 成功:' + msg.successCount + ' 失败:' + msg.errorCount;
			resultMsg = resultMsg + '<a href="#" onclick="openMsgDlg()" > 查看</a>';

			$('#resultMsg').html(resultMsg);
			$('#recordMsg').html(msg.recordMsg);
			$('#filePathId').val(null);
			$('#dg').datagrid('reload');

			$('#InductionButtons').linkbutton({
				disabled : true
			});
		} else {
			$.messager.alert('导入出错', msg.errorMsg);
		}
		$('#batchDlg').unmask();
	});
}

/**
 *  批量导入
 */
function importExcel() {
	$('#filePathId').val(null);
	$('#uploadMsg').html("请先上传EXCEL文件");
	$('#InductionButtons').linkbutton({
		disabled : true
	});
	$('#batchDlg').dialog({
		modal : true
	}).dialog('open').dialog('setTitle', '批量导入');
}

function checkType() {
	var file = $('#fileInput');
	var val = file.val();
	if (val) {
		var suffix = val.substring(val.lastIndexOf("."));
		if (suffix != ".xls") {
			$.messager.alert('系统提示', '格式不正确,请选择xls文件！');
			file.after(file.clone().val(""));
			file.remove();
			return false;
		}
		return true;
	} else if (val == "") {
		return true;
	}
}

function openMsgDlg() {
	$('#msgDlg').dialog({
		modal : true
	}).dialog('open').dialog('setTitle', '错误记录');
}